const AMap = window.AMap;
const getAddress = function getAddress(lng, lat) {
  return new Promise((resolve, reject) => {
    var map = new AMap.Map("container", {
      resizeEnable: true,
      zoom: 18,
    });
    var lnglatXY = [lng, lat]; //已知点坐标
    var geocoder = new AMap.Geocoder({
      city: "010", //城市设为北京，默认：“全国”
      radius: 1000, //范围，默认：500
    });

    geocoder.getAddress(lnglatXY, (status, result) => {
      console.log("status, result=", status, result);
      var currentAddress;
      if (status === "complete" && result.info === "OK") {
        currentAddress = result.regeocode.formattedAddress;
      } else {
        currentAddress = "暂无站点位置";
      }
      resolve(currentAddress);
    });
    var marker = new AMap.Marker({
      //加点
      map: map,
      position: lnglatXY,
    });
    map.setFitView();
  });
};
export default getAddress;
